package cn.stl.org.service.Imp;

import cn.stl.basic.util.PageList;
import cn.stl.org.domain.Department;
import cn.stl.org.mapper.DepartmentMapper;
import cn.stl.org.query.DepartmentQuery;
import cn.stl.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void save(Department department) {
         departmentMapper.save(department);
    }

    @Override
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    public List<Department> loadAll() {

        return departmentMapper.loadAll();
    }

    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {
        Long count = departmentMapper.queryCount(departmentQuery);
        if (count == 0){
            return new PageList<>();
        }
        List<Department> rows = departmentMapper.queryData(departmentQuery);
        PageList<Department> pageList = new PageList<>(count, rows);
        return pageList;
    }
}
